<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <ul>
      <li>1</li>
      <li>1</li>
      <li>1</li>
      <li>1</li>
    </ul>

    <script>
      //要判断的对象 instanceof 要判断的数据类型
      //判断复杂数据类型 就看右边的原型对象是否在左边的原型链上

      // instanceof 关键词手写
      function instanceOf(father, child) {
        const fp = father.prototype
        var cp = child.__proto__

        while (cp) {
          if (cp === fp) {
            return ture
          }
          cp = cp.__proto__
        }

        return false
      }

      //   const obj = {}

      //   const arr = []

      //   const fn = function () {}

      //   console.log(obj instanceof Object)
      //   console.log(arr instanceof Array)
      //   console.log(fn instanceof Function)

      //   console.log(obj instanceof Object)
      //   console.log(arr instanceof Object)
      //   console.log(fn instanceof Object)

      //   function Fn(a) {
      //     this.a = a
      //   }

      //   const obj = new Fn(1)

      //   console.log(obj instanceof Fn)

      //typeof 判断基本数据类型

      //   let str = '123'
      //   let num = 123

      //   const arr = []

      //   console.log(typeof str)
      //   console.log(typeof num)
      //   console.log(typeof arr)
      //   console.log(typeof null)

      //Object.prototype.toString 最准确的判断类型的方式，最推荐的！！！

      const arr = [1, 2, 3]
      const fn = () => {}
      const obj = {}

      //   console.log(arr)
      //   console.log(arr.toString())

      //   console.log(Object.prototype.toString.call(arr) === '[object Array]')
      //   console.log(Object.prototype.toString.call(fn) === '[object Function]')
      //   console.log(Object.prototype.toString.call(obj) === '[object Object]')
      //   console.log(Object.prototype.toString.call('123'))
      //   console.log(Object.prototype.toString.call(123))
      //   console.log(Object.prototype.toString.call(true))
      //   console.log(Object.prototype.toString.call(undefined))
      //   console.log(Object.prototype.toString.call(null))

      const lis = document.querySelectorAll('li')
      console.log(Array.isArray(arr))
      console.log(Array.isArray(obj))
      console.log(Array.isArray(lis))
    </script>
  </body>
</html>
